<?php
	class Shepherd_AdministrationController extends Sss_Controller_Shepherd
	{
		private $_menuName = 'Administration';
		public function init()
		{
			parent::init();
			$this->checkInstance();
			$handle           = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			if ($userInformation->username != Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT || !$userInformation->username) {
				$this->_redirect("/$handle/user/login");
			}
		}
		public function indexAction()
		{
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$this->_redirect("/$handle/administration/user");
		}
		public function userAction()
		{
			$accountTable = new Shepherd_Model_Mapper_Account();
			$assignmentTable = new Shepherd_Model_Mapper_Assignment();
			$instanceTable   = new Application_Model_Mapper_Instance();
			$get  = $this->getRequest()->getParams();
			$isSearch = isset($get['s']) && $get['s'] == 1;
			//get order, page, limit param
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
			//param filter: omit title text in field
			$paramUserName = $isSearch ? strcmp($this->getRequest()->getParam('username', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('USER_NAME')) == 0 ? '' : $this->getRequest()->getParam('username', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
			$paramFullName = $isSearch ? strcmp($this->getRequest()->getParam('fullname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('FULL_NAME')) == 0 ? '' : $this->getRequest()->getParam('fullname', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
			$paramRoleName = $isSearch ? strcmp($this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ROLE')) == 0 ? '' : $this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
			//get filter
			$filterParam['username'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'username', trim($paramUserName), Sss_Ultility_SessionName::ACCOUNT_SESSION);
			$filterParam['fullname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'fullname', trim($paramFullName), Sss_Ultility_SessionName::ACCOUNT_SESSION);
			$filterParam['rolename'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'rolename', trim($paramRoleName), Sss_Ultility_SessionName::ACCOUNT_SESSION);

			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			//delete user
			$accountId = $this->getRequest()->getParam('accountid', -1);
			//get information of intance and user
			$instance = $instanceTable->getInstanceByHandle($handle);
			$user = $accountTable->getUserById($accountId,$instance->instanceid);
			if ($userInformation->username && isset($accountId) && $accountId != -1) {
				$account = $accountTable->findById($accountId,$instance->instanceid);
				$account->setIsArchived(1);
				$deleteId = $accountTable->save($account,$instance->instanceid);
				if (isset($deleteId)) {
					//Remove report, dashboards shepherd BI and delete user
					try {
						Sss_Ultility_Common::deleteUserBi($instance->instanceid.$user->username,$instance->instanceid);
					} catch(Exception $e) {
						Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
					}
					//End remove
					$assignmentByAccount = $assignmentTable->getRoleByAccount($accountId);
					$assignmentTable->deleteRow($assignmentByAccount->assignmentid,$instance->instanceid);
					//Delete user in OTRS service when delete user in shepherd site
					$otrs = new Sss_Ultility_OtrsServices();
					if($account){
						$fullName = $account->getFullName();
						$userName = $account->getUserName().$accountId.$handle;
						$email = $accountId.$handle.$account->getEmail();
						$otrs->deleteCustomer(USER_SERVICE_ID , 2, $fullName, $userName, $email, USER_SERVICE, PASSWORD_SERVICE);
					}
					$message = Resources::_('DELETE_USER_SUCCESSFULL');
				} else {
					$message = Resources::_('DELETE_USER_FAIL');
				}
				$this->redirect($message, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
				)));
			}
			//reset password
			$resetId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::RESET_PASSWORD_ID, -1);
			if ($userInformation->username && isset($resetId) && $resetId != -1) {
				try {
					$account = $accountTable->getById($resetId);
					$result = Sss_Ultility_AdministrationFunction::resetPassword($account, $get, $resetId, $handle);
				} catch (exception $e) {
					$result = Resources::_('RESET_PASSWORD_FAIL');
				}
				$this->redirect($result, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
				)));
			}
			$list       = $accountTable->getList($this->view->limit, 0, $filterParam, 1);
			$row        = $list->list;
			$pagination = $list->pagination;
			$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
			$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);

			$arrQueryString = Sss_Ultility_AdministrationFunction::getQueyString($isSearch, $filterParam);
			$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $arrQueryString['querystring']);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $arrQueryString['oquerystring']);
			//action button
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'add-user', Resources::_('ADD_NEW_USER')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::LISTITEM, 'role', Resources::_('LIST_ROLE')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'user-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'user-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('USER'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function addUserAction()
		{
			$accountTable = new Shepherd_Model_Mapper_Account();
			$assignmentTable = new Shepherd_Model_Mapper_Assignment();
			$roleTable = new Shepherd_Model_Mapper_Role();
			$instanceTable   = new Application_Model_Mapper_Instance();
			$permissionTable = new Shepherd_Model_Mapper_Permission();
			//get list role
			$roles = $roleTable->getList();
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $roles);
			$params = $this->_request->getParams();
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
			$instanceId = $defaultOvisNamespace->dbShepherd;
			//insert user and user role
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
				if ($userInformation->username) {
					//Process adding new user  
					$list = $accountTable->getUserList();
					foreach ($list as $l) {
						if (trim($l['username']) == trim($params['username'])) {
							$this->redirect(Resources::_('USER_NAME_EXIST'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)));
						}
						if (trim($l['email']) == trim($params['email'])) {
							$this->redirect(Resources::_('EMAIL_EXIST'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)));
						}
					}
					$passWordDefault   = Sss_Ultility_Common::genRandomString();
					$encryptedPassword = Sss_Crypt::factory()->encrypt($passWordDefault);
					$isActived = isset($params['isactivated']) ? 1 : 0;
					$userName = addslashes($params['username']);
					$fullName = addslashes($params['fullname']);
					$email = addslashes($params['email']);
					$accountContructor = new Shepherd_Model_Account();
					$accountContructor->setUsername($userName);
					$accountContructor->setFullname($fullName);
					$accountContructor->setPassword($encryptedPassword);
					$accountContructor->setAddress(addslashes($params['address']));
					$accountContructor->setPhone(addslashes($params['phone']));
					$accountContructor->setEmail($email);
					$accountContructor->setIsActivated($isActived);
					$accountContructor->setIsArchived(0);
					$accountContructor->setIsBlock(0);
					$accountContructor->setSalt(0);
					$accountContructor->setIsSystem(0);
					$accountId = $accountTable->save($accountContructor,$instanceId);
					if (isset($accountId)) {
						$otrs = new Sss_Ultility_OtrsServices();
						// Get service OTRS and create new user OTRS relation with user ovis account
						$arrParams = array();
						$arrParams['fullname'] =  $fullName;
						$arrParams['username'] =  $userName.$accountId.$handle;
						$arrParams['password'] =  $encryptedPassword;
						$arrParams['email'] =  $accountId.$handle.$email;
						$arrParams['wsuser'] =  USER_SERVICE;
						$arrParams['wspass'] =  PASSWORD_SERVICE;
						$user_otrs_id   = $otrs->createCustomerUser(USER_SERVICE_ID, 1, $arrParams);


						$list = $accountTable->getUserList(); 
						$listAccountIds = '';
						foreach ($list as $l) {
							if ($listAccountIds == '' && $l['otrs_user_id'] != '') {
								$listAccountIds = $l['otrs_user_id'];
							} elseif($listAccountIds != '' && $l['otrs_user_id'] == '') {
								$listAccountIds = $listAccountIds;
							} else {
								$listAccountIds = $l['otrs_user_id'].','.$listAccountIds;
							}
						}
						foreach ($list as $l) {
							if(is_null($l['customer_ids'])){
							$emailUpdate = $l['accountid'].$handle.$l['email'];
							$userLogin =    $l['username'].$l['accountid'].$handle;
							$otrs->updateCustomerUser(USER_SERVICE_ID, 1, $l['fullname'], $userLogin, $userLogin,$emailUpdate , USER_SERVICE, PASSWORD_SERVICE, $listAccountIds);
							$account = $accountTable->findById($l['accountid'],$instance->instanceid);
							$account->setCustomerIds($listAccountIds);
							$accountTable->save($account,$instanceId);
							}
						}
						$otrs->updateCustomerUser(USER_SERVICE_ID, 1, $fullName, $userName.$accountId.$handle,$userName.$accountId.$handle,$accountId.$handle.$email, USER_SERVICE, PASSWORD_SERVICE, $listAccountIds);
						$account = $accountTable->findById($accountId,$instance->instanceid);
						$account->setOtrsUserId($user_otrs_id);
						$account->setCustomerIds($listAccountIds);
						$accountTable->save($account,$instanceId);
						//Assign account to group OTRS when add new 
						$instance = $instanceTable->getInstanceByHandle($handle);
						if($instance && !is_null($instance->otrs_group)) {
							$otrs->assignCustomer2Group(USER_SERVICE_ID, $userName.$accountId.$handle, null, $instance->otrs_group, USER_SERVICE, PASSWORD_SERVICE);
						}
						//Process adding assignment
						$assignment = new Shepherd_Model_Assignment();
						$assignment->setRole($params['role']);
						$assignment->setAccount($accountId);
						$assignmentTable->save($assignment,$instanceId);

						try {
							$activateCode   = Sss_Ultility_Common::genRandomString(75);
							$email             = $params['email'];
							$account = $accountTable->findById($accountId,$instanceId);
							$account->setActivateCode($activateCode);
							$accountTable->save($account,$instanceId);
							$subject = Resources::_('SUBJECT_ADD');
							$body =  $body    = Resources::_('DEAR').' '.$params['fullname'].',' . " \n \n"
							. Resources::_('BODY_ADD') . " \n \n"
							. Resources::_('PASSWORD') . ": ". $passWordDefault . " \n \n"
							. Resources::_('BODY14_1'). " \n \n"
							. Resources::_('BODY5'). " \n"
							. Resources::_('BODY6');
							if($isActived == 0) {
								$body    = Resources::_('DEAR').' '.$params['fullname'].',' . " \n \n"
								. Resources::_('BODY_ADD') . " \n \n"
								. Resources::_('BODY2').' '.DOMAIN_SYSTEM."/$handle/active/active?activatecode=$activateCode&popup=1"." \n \n"
								. Resources::_('USERNAME').' '. $params['username']
								. " \n"
								. Resources::_('PASSWORD') . ": ". $passWordDefault. " \n \n"
								. Resources::_('BODY14_1'). " \n \n"
								. Resources::_('BODY5'). " \n"
								. Resources::_('BODY6');
							}
							// add user shepherd BI
							$instance = $instanceTable->getInstanceByHandle($handle);
							$user = $instance->instanceid.$userName;
							$dataRole = $permissionTable->getByRoleId($params['role'],Sss_Ultility_CommonViewParamater::ANALYSIS);
							try {
								Sss_Ultility_Common::addUserAndDashboard($user,$encryptedPassword,$fullName,$instance->instanceid,$dataRole);
							} catch(Exception $e) {
								Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
							}
							//End add user shepherd BI
							Sss_Ultility_Common::sendMail(EMAIL_SYSTEM, $email, $subject, $body);
							$this->redirect(Resources::_('ADD_USER_SUCCESSFULL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => 'user'
							)));
						}
						catch (exception $e) {
							Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
							$this->redirect(Resources::_('ADD_USER_FAIL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => 'user'
							)));
						}
					} else {
						$this->redirect(Resources::_('ADD_USER_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'user'
						)));
					}
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('USER'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_USER'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function editUserAction()
		{
			$accountTable = new Shepherd_Model_Mapper_Account();
			$assignmentTable = new Shepherd_Model_Mapper_Assignment();
			$roleTable = new Shepherd_Model_Mapper_Role();
			$instanceTable   = new Application_Model_Mapper_Instance();
			$permissionTable = new Shepherd_Model_Mapper_Permission();
			//get list role
			$roles = $roleTable->getList();
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$instance = $instanceTable->getInstanceByHandle($handle);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $roles);
			$params = $this->_request->getParams();
			$accountId = $this->getRequest()->getParam('accountid', -1);
			if (($accountId == -1 || (int) $accountId == 0) && isset($params['accountid']))
				$accountId = $params['accountid'];
			$this->view->assign('accountid', $accountId);
			//get account
			$account = $accountTable->getById($accountId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACCOUNT, $account);
			//insert user and user role
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
				if ($userInformation->username) {
					//Process adding new user  
					$queryString = '?accountid=' . $accountId;
					$list        = $accountTable->getUserList($accountId);
					foreach ($list as $l) {
						if (trim($l['username']) == trim($params['username'])) {
							$this->redirect(Resources::_('USER_NAME_EXIST'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)) . $queryString);
						}
						if (trim($l['email']) == trim($params['email'])) {
							$this->redirect(Resources::_('EMAIL_EXIST'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)) . $queryString);
						}
					}
					$isActivated = isset($params['isactivated']) ? 1 : 0;
					$account = $accountTable->findById($accountId,$instance->instanceid);
					$account->setUserName(addslashes($params['username']));
					$account->setFullName(addslashes($params['fullname']));
					$account->setAddress(addslashes($params['address']));
					$account->setPhone(addslashes($params['phone']));
					$account->setEmail(addslashes($params['email']));
					$account->setIsActivated($isActivated);
					$id = $accountTable->save($account,$instance->instanceid);
					if (isset($id)) {
						if(addslashes($params['username']) != $account->getUserName()) {
							try {
								// add user shepherd BI
								$user = $instance->instanceid.addslashes($params['username']);
								$dataRole = $permissionTable->getByRoleId($params['role'],Sss_Ultility_CommonViewParamater::ANALYSIS);
								Sss_Ultility_Common::addUserAndDashboard($user,$account->getPassword(),addslashes($params['fullname']),$instance->instanceid,$dataRole);
								//End add user
								//Remove user old
								Sss_Ultility_Common::deleteUserBi($instance->instanceid.$account->getUserName(),$instance->instanceid);
								//End remove
							} catch(Exception $e) {
								Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
							}
						}
						//Process adding assignment
						$assignmentAccount = $assignmentTable->getRoleByAccount($accountId);
						$assignment = $assignmentTable->findById($assignmentAccount->assignmentid,$instance->instanceid);
						$assignment->setRole($params['role']);
						$assignmentId = $assignmentTable->save($assignment,$instance->instanceid);
						
						$this->redirect(Resources::_('EDIT_USER_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'user'
						)));
					} else {
						$this->redirect(Resources::_('EDIT_USER_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'user'
						)));
					}
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('USER'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_USER'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function roleAction()
		{
			$roleTable = new Shepherd_Model_Mapper_Role();
			$accountTable = new Shepherd_Model_Mapper_Account();

			$get  = $this->getRequest()->getParams();
			$isSearch = isset($get['s']) && $get['s'] == 1;
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
			$instanceId = $defaultOvisNamespace->dbShepherd;
			//get order, page, limit param
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;                
			$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

			//param filter: omit title text in field
			$paramRoleName = $isSearch ? strcmp($this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ROLE_NAME')) == 0 ? '' : $this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

			//get filter
			$filterParam['rolename'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'rolename', trim($paramRoleName), Sss_Ultility_SessionName::ROLE_SESSION);

			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			if ($userInformation->username) {
				//delete role
				$roleId = $this->getRequest()->getParam('roleid', -1);

				if (isset($roleId) && $roleId != -1) {
					$userInRole = $accountTable->checkUserInRole($roleId);
					if($userInRole){
						$this->redirect(Resources::_('ROLE_EXIST'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
						)));
					} else {
						$deleteId = $roleTable->deleteRow($roleId,$instanceId);
						if (isset($deleteId)) {
							$this->redirect(Resources::_('DELETE_ROLE_SUCCESSFULL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)));
						} else {
							$this->redirect(Resources::_('DELETE_ROLE_FAIL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
							)));
						}
					}
				}
			}

			$list       = $roleTable->getRoleList($this->view->limit, 0, $filterParam);
			$row        = $list->list;
			$pagination = $list->pagination;
			$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
			$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);

			$arrQueryString = Sss_Ultility_AdministrationFunction::getQueyString($isSearch, $filterParam);
			$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $arrQueryString['querystring']);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $arrQueryString['oquerystring']);

			//action button
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'add-role', Resources::_('ADD_NEW_ROLE')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::LISTITEM, 'user', Resources::_('LIST_USER')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ROLE'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function addRoleAction()
		{
			$roleTable = new Shepherd_Model_Mapper_Role();

			$params = $this->_request->getParams();
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
			$instanceId = $defaultOvisNamespace->dbShepherd;
			//insert role
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
				if ($userInformation->username) {
					$isUsed = isset($params['isused']) ? 1 : 0;
					$role = new Shepherd_Model_Role();
					$role->setRoleName(addslashes($params['rolename']));
					$role->setIsused($isUsed);
					//Process adding role
					$id = $roleTable->save($role,$instanceId);
					if (isset($id)) {
						$this->redirect(Resources::_('ADD_ROLE_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'role'
						)));
					} else {
						$this->redirect(Resources::_('ADD_ROLE_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'role'
						)));
					}
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ROLE'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_ROLE'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function editRoleAction()
		{
			$roleTable = new Shepherd_Model_Mapper_Role();

			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$defaultOvisNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::OVIS_SHEPHERD_SYSTEM . $handle);
			$instanceId = $defaultOvisNamespace->dbShepherd;
			$params = $this->_request->getParams();

			$roleId = $this->getRequest()->getParam('roleid', -1);
			if (($roleId == -1 || (int) $roleId == 0) && isset($params['roleid']))
				$roleId = $params['roleid'];
			$this->view->assign('roleid', $roleId);

			//get role
			$role = $roleTable->getById($roleId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROLE, $role);

			//update role
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
				if ($userInformation->username) {
					$isUsed = isset($params['isused']) ? 1 : 0;
					$role = $roleTable->findById($roleId,$instanceId);
					$role->setRoleName(addslashes($params['rolename']));
					$role->setIsUsed($isUsed);
					$Id = $roleTable->save($role,$instanceId);
					if (isset($Id)) {
						$this->redirect(Resources::_('EDIT_ROLE_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'role'
						)));
					} else {
						$this->redirect(Resources::_('EDIT_ROLE_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'role'
						)));
					}
				}
			}

			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ROLE'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_ROLE'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function rightsAction()
		{
			$permissionTable = new Shepherd_Model_Mapper_Permission();

			$assignmentTable = new Shepherd_Model_Mapper_Assignment();
			$instanceTable  = new Application_Model_Mapper_Instance();

			$params = $this->_request->getParams();
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);

			$roleId = $this->getRequest()->getParam('roleid', -1);
			if (($roleId == -1 || (int) $roleId == 0) && isset($params['roleid']))
				$roleId = $params['roleid'];
			$this->view->assign('roleid', $roleId);
			
			$permissionByRole = $permissionTable->getByRoleId($roleId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::PERMISSION, $permissionByRole);
			//update role
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $roleId != -1) {
				try {
					$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
					if ($userInformation->username) {
						if($userInformation->username == Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT) {
							//get information report and dashboard
							$listUser = $assignmentTable->getListAccountByRole($roleId); 
							//$client = Sss_Ultility_Common::connectShepherdBI();
							$instance = $instanceTable->getInstanceByHandle($handle);
							//End get information 
							$arrRoleId = array('role = ?' => $roleId); 
							$id = $permissionTable->deleteRow(null, $arrRoleId,$instance->instanceid);
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN_SELECT])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN_SELECT]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN_EDIT])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_FlOOR_PLAN_EDIT]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_DYNAMIC_MONITORING])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_DYNAMIC_MONITORING);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_GRAPHS])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_GRAPHS);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_GEOMAPPING])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_GEOMAPPING);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_CONFIGURATION])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_CONFIGURATION);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_ADD])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_ADD]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_EDIT])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_EDIT]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_DELETE])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_DELETE]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_VISIBLE])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION_VISIBLE]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_ADD])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SHIPMENT);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_ADD]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_EDIT])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SHIPMENT);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_EDIT]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_DELETE])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SHIPMENT);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_DELETE]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_VISIBLE])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SHIPMENT);
								$permission->setAction($params[Sss_Ultility_CommonViewParamater::PER_SHIPMENT_VISIBLE]);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_RMA])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_RMA);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_ANALYSIS])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_ANALYSIS);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
								// add permission list user in role shepherd BI
								try {
									foreach($listUser as $user) {
										Sss_Ultility_Common::addUserAndDashboard($instance->instanceid.$user['username'],$user['password'],$user['fullname'],$instance->instanceid,$params[Sss_Ultility_CommonViewParamater::PER_ANALYSIS]);
									}
								} catch(Exception $e) {
									Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
								}
								//End
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SUPPORT_OTRS])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SUPPORT_OTRS);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SUPPORT_MANUALS])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SUPPORT_MANUALS);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_SUPPORT_SLA])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_SUPPORT_SLA);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							if (isset($params[Sss_Ultility_CommonViewParamater::PER_MY_HARDWARE])) {
								$permission = new Shepherd_Model_Permission();
								$permission->setRole($roleId);
								$permission->setFeature(Sss_Ultility_CommonViewParamater::PER_MY_HARDWARE);
								$permission->setAction(Sss_Ultility_CommonViewParamater::ALL);
								$id   = $permissionTable->save($permission,$instance->instanceid);
							}
							//Remove report and dashboards shepherd BI
							if (!isset($params[Sss_Ultility_CommonViewParamater::PER_ANALYSIS])) {
								try {
									foreach($listUser as $user) {
										$valueCheck = array(
										'virtualUserName'   => $instance->instanceid.$user['username']
										);
										$check = $client->ExistedUser($valueCheck);
										if($check->return == true) {
											Sss_Ultility_Common::removeDashboardAndRrport($instance->instanceid.$user['username'],$instance->instanceid);
										}
									}
								} catch(Exception $e) {
									Sss_Ultility_Common::logger()->log($e, Zend_Log::ERR);
								}
							}
							//End remove
						}
						$this->redirect(Resources::_('ADD_PERMISSION_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'role'
						)));
					}
				} catch (exception $e) {
					$this->redirect(Resources::_('ADD_PERMISSION_FAIL'), $this->view->url(array(
					Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
					Sss_Ultility_CommonViewParamater::ACTION => 'role'
					)));
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('RIGHTS_MANAGEMENT'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
		public function userExportAction()
		{
			$accountTable = new Shepherd_Model_Mapper_Account();


			//get order, page, limit param
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
			$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;                
			$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
			//param filter: omit title text in field
			$paramUserName = strcmp($this->getRequest()->getParam('username', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('USER_NAME')) == 0 ? '' : $this->getRequest()->getParam('username', Sss_Ultility_CommonViewParamater::UNDERFINE);

			$paramFullName = strcmp($this->getRequest()->getParam('fullname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('FULL_NAME')) == 0 ? '' : $this->getRequest()->getParam('fullname', Sss_Ultility_CommonViewParamater::UNDERFINE);

			$paramRoleName = strcmp($this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ROLE')) == 0 ? '' : $this->getRequest()->getParam('rolename', Sss_Ultility_CommonViewParamater::UNDERFINE);

			//get filter
			$filterParam['username'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'username', trim($paramUserName), Sss_Ultility_SessionName::ACCOUNT_SESSION);
			$filterParam['fullname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'fullname', trim($paramFullName), Sss_Ultility_SessionName::ACCOUNT_SESSION);
			$filterParam['rolename'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'rolename', trim($paramRoleName), Sss_Ultility_SessionName::ACCOUNT_SESSION);

			$list       = $accountTable->getList(-1, 0, $filterParam, 1);
			$rowAll        = $list->list;
			$pagination = $list->pagination;
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);  
			$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
			$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
			$columnNames = array(
			Resources::_('ID'),
			Resources::_('USER_NAME'),
			Resources::_('FULL_NAME'),
			Resources::_('ROLE'),
			Resources::_('STATUS') 
			);
			$arrData = array();
			$index = 0;
			foreach((array)$rowAll as $row) {
				$count++;
				$arrData[$index][] = $count;
				$arrData[$index][] = $row['username'];
				$arrData[$index][] = $row['fullname'];
				$arrData[$index][] = $row['rolename'];
				$arrData[$index][] = $row['isactivated'] == true ? Resources::_('ACTIVATED'): Resources::_('IN_ACTIVATED');
				$index++;
			}
			if(isset($_GET['export']))
				$this->exportDataToExcel($columnNames, $arrData, Resources::_('USERS'));
		}
		public function contactInformationAction()
		{
			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);

			//check permission
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_STOCK_LOCATION, Sss_Ultility_CommonViewParamater::VISIBLE, 'feature', 'action' ,$this->listRole(), true) == 1 ){

				$accountTable = new Application_Model_Mapper_Account();
				$inventoryTable = new Application_Model_Mapper_Inventory();

				$defaultNamespace = new Zend_Session_Namespace(Sss_Ultility_SessionName::SHEPHERD_SYSTEM . $handle);
				$stockLocationId = $defaultNamespace->stocklocationId;

				//get stock location by id
				$stockLocation = Sss_Ultility_Common::getInforStockLocation($stockLocationId);
				$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION, $stockLocation);

				$inventory           = $inventoryTable->getInventoryByStockLocation($stockLocationId);
				$this->view->assign(Sss_Ultility_CommonViewParamater::INVENTORY, $inventory);

				//get company owner account name
				$compnayOwner           = $accountTable->getCompanyOwnerByStockLocation($stockLocationId);
				$compnayOwnerName = '';
				foreach($compnayOwner as $c) {
					if($compnayOwnerName != '') {
						$compnayOwnerName = $compnayOwnerName.', ';
					}
					$compnayOwnerName = $compnayOwnerName.$c['fullname'];
				}
				$this->view->assign(Sss_Ultility_CommonViewParamater::ACCOUNT, $compnayOwnerName);

				//action button
				$actionbuttons = array(
				new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, '/'.$handle.'/administration/user', Resources::_('BTN_BACK'))
				);
				$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);

				//get breadscrumb
				$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('CONTACT_INFORMATION'), '#')
				);
				$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);

				// check rights for edit stock information
				$lstRoles = $this->listRole();
				$isEdited = false;
				if ($userInformation->username == Sss_Ultility_CommonViewParamater::USER_NAME_SHEPHERD_DEFAULT) {
					$isEdited = true;
				} else {
					foreach ($lstRoles as $role) {
						if ($role['feature'] == 'stock-location' && $role['action'] == 'edit') {
							$isEdited = true;
						}
					}
				}
				$this->view->assign('isEdited', $isEdited);
			} else {
				$this->_redirect("/$handle/inventory/shipment");
			}
		}
	}
